﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.DAO;

namespace ERP_RORZE.Product.Quotation
{
    public partial class frm_QMaterialAdd : DevExpress.XtraEditors.XtraForm
    {
        public event EventHandler Reload;
        ClsQuationDAO clsQuotationDAO = new ClsQuationDAO();
        ClsPartDataDAO clsPartDataDAO = new ClsPartDataDAO();
        ClsMachineDAO clsMachineDAO = new ClsMachineDAO();
        DataTable dt;
        QMaterial b = new QMaterial();

        public frm_QMaterialAdd()
        {
            InitializeComponent();
        }

        private void frm_QMaterialAdd_Load(object sender, EventArgs e)
        {
            dt = clsQuotationDAO.GetAllQuotation();
            cbQuotationID.DataSource = dt;
            cbQuotationID.DisplayMember = "QuotationID";
            cbQuotationID.ValueMember = "QuotationID";

            //
            dt = clsPartDataDAO.GetAllPartID();
            cbMPartNo.DataSource = dt;
            cbMPartNo.DisplayMember = "PartNo";
            cbMPartNo.ValueMember = "PartNo";

            //
            dt = clsPartDataDAO.GetAllMaterial();
            cbMaterialID.DataSource = dt;
            cbMaterialID.DisplayMember = "MaterialID";
            cbMaterialID.ValueMember = "MaterialID";
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtThickness.Text == "")
            {
                MessageBox.Show("Chưa nhập Thickness");
            }
            else if (txtLength.Text == "")
            {
                MessageBox.Show("Chưa nhập Lenght");
            }
            else
            {
                try
                {
                    b.MaterialPrice = int.Parse(txtMaterialPrice.Text);
                    b.Length = int.Parse(txtLength.Text);
                    b.Price = int.Parse(txtPrice.Text);
                    b.Thickness = int.Parse(txtThickness.Text);
                    b.Width = int.Parse(txtWidth.Text);
                    b.MaterialType = txtMaterialType.Text;
                    b.Note = txtNote.Text;
                    b.QuotationID = cbQuotationID.Text;
                    b.MaterialID = cbMaterialID.Text;
                    b.MPartNo = cbMPartNo.Text;
                    b.Shape = cbShape.Text;
                    clsQuotationDAO.InsertQuotationMaterial(b);
                    Reload(sender,e);
                }
                catch
                {
                    MessageBox.Show("MaterialPrice, Thickness, Length, Width, Price  phải là kiểu số");
                }
            }
        }
    }
}